<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-flash.min.css?v=1.0.2" rel="stylesheet">




  
  
  <link rel="stylesheet" media="all" href="/lib/Han/dist/han.min.css?v=3.3">




<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="规范,">





  <link rel="alternate" href="/atom.xml" title="Colin's Blog" type="application/atom+xml">






<meta name="description" content="Dart 风格指南好的代码令人惊讶的重要部分是好的样式。一致的命名，排序和格式有助于代码是相同的外观相同。如果我们在整个Dart生态系统中使用一致的样式，那么这将使我们所有人更容易学习彼此的代码并做出贡献。 风格类型标识符在Dart中具有三种风格。  UpperCamelCase 大驼峰名称将每个单词的首字母大写，包括第一个。  lowerCamelCase 小驼峰名称为每个字的第一个字母，除了">
<meta name="keywords" content="规范">
<meta property="og:type" content="article">
<meta property="og:title" content="Dart 风格指南">
<meta property="og:url" content="http://duanyitao.com/2020/03/12/Dart-风格指南/index.html">
<meta property="og:site_name" content="Colin&#39;s Blog">
<meta property="og:description" content="Dart 风格指南好的代码令人惊讶的重要部分是好的样式。一致的命名，排序和格式有助于代码是相同的外观相同。如果我们在整个Dart生态系统中使用一致的样式，那么这将使我们所有人更容易学习彼此的代码并做出贡献。 风格类型标识符在Dart中具有三种风格。  UpperCamelCase 大驼峰名称将每个单词的首字母大写，包括第一个。  lowerCamelCase 小驼峰名称为每个字的第一个字母，除了">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2020-03-12T10:46:05.403Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Dart 风格指南">
<meta name="twitter:description" content="Dart 风格指南好的代码令人惊讶的重要部分是好的样式。一致的命名，排序和格式有助于代码是相同的外观相同。如果我们在整个Dart生态系统中使用一致的样式，那么这将使我们所有人更容易学习彼此的代码并做出贡献。 风格类型标识符在Dart中具有三种风格。  UpperCamelCase 大驼峰名称将每个单词的首字母大写，包括第一个。  lowerCamelCase 小驼峰名称为每个字的第一个字母，除了">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":20,"b2t":true,"scrollpercent":true,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://duanyitao.com/2020/03/12/Dart-风格指南/">





  <title>Dart 风格指南 | Colin's Blog</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Colin's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <h1 class="site-subtitle" itemprop="description">时间是没有声音的锉刀。</h1>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-android">
          <a href="/categories/Android/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-android"></i> <br>
            
            Android
          </a>
        </li>
      
        
        <li class="menu-item menu-item-kotlin">
          <a href="/categories/Kotlin/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-code"></i> <br>
            
            Kotlin
          </a>
        </li>
      
        
        <li class="menu-item menu-item-dart">
          <a href="/categories/Dart/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-terminal"></i> <br>
            
            Dart
          </a>
        </li>
      
        
        <li class="menu-item menu-item-flutter">
          <a href="/categories/Flutter/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-road"></i> <br>
            
            Flutter
          </a>
        </li>
      
        
        <li class="menu-item menu-item-ios">
          <a href="/categories/iOS/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-apple"></i> <br>
            
            iOS
          </a>
        </li>
      
        
        <li class="menu-item menu-item-web">
          <a href="/categories/Web/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-html5"></i> <br>
            
            Web
          </a>
        </li>
      
        
        <li class="menu-item menu-item-vim">
          <a href="/categories/Vim/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-code"></i> <br>
            
            Vim
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://duanyitao.com/2020/03/12/Dart-风格指南/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="段燚涛">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Colin's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h2 class="post-title" itemprop="name headline">Dart 风格指南</h2>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-03-12T09:58:35+08:00">
                2020-03-12
              </time>
            

            
              <span class="post-meta-divider">|</span>
            

            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-check-o"></i>
              </span>
              
                <span class="post-meta-item-text">更新于&#58;</span>
              
              <time title="更新于" itemprop="dateModified" datetime="2020-03-12T18:46:05+08:00">
                2020-03-12
              </time>
            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Dart/" itemprop="url" rel="index">
                    <span itemprop="name">Dart</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2.1k
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  8
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body han-init-context" itemprop="articleBody">

      
      

      
        <h1 id="Dart-风格指南"><a href="#Dart-风格指南" class="headerlink" title="Dart 风格指南"></a>Dart 风格指南</h1><p>好的代码令人惊讶的重要部分是好的样式。一致的命名，排序和格式有助于代码是相同的外观相同。如果我们在整个Dart生态系统中使用一致的样式，那么这将使我们所有人更容易学习彼此的代码并做出贡献。</p>
<h2 id="风格类型"><a href="#风格类型" class="headerlink" title="风格类型"></a>风格类型</h2><p>标识符在Dart中具有三种风格。</p>
<ul>
<li><p>UpperCamelCase 大驼峰名称将每个单词的首字母大写，包括第一个。</p>
</li>
<li><p>lowerCamelCase 小驼峰名称为每个字的第一个字母，除了 第一它总是小写，即使它是一个缩写。</p>
</li>
<li><p>lowercase_with_underscores 小写字母+下划线。仅使用小写字母（即使是首字母缩写词），并使用下划线分隔单词。</p>
</li>
</ul>
<h2 id="类型使用大驼峰法"><a href="#类型使用大驼峰法" class="headerlink" title="类型使用大驼峰法"></a>类型使用大驼峰法</h2><p>Classes, enums, typedefs, 和 Type parameters 使用大驼峰，并且不使用分隔符。</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">SliderMenu</span> </span>&#123; ... &#125;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">HttpRequest</span> </span>&#123; ... &#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> Predicate&lt;T&gt; = <span class="built_in">bool</span> <span class="built_in">Function</span>(T value);</span><br></pre></td></tr></table></figure>
<p>包括注解类型也使用大驼峰：</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Foo</span> </span>&#123;</span><br><span class="line">  <span class="keyword">const</span> Foo([arg]);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Foo</span>(anArg)</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">A</span> </span>&#123; ... &#125;</span><br><span class="line"></span><br><span class="line"><span class="meta">@Foo</span>()</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">B</span> </span>&#123; ... &#125;</span><br></pre></td></tr></table></figure>
<p>如果注解类的构造函数不接受参数，您可能希望为它创建一个单独的lowerCamelCase常量。</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> foo = Foo();</span><br><span class="line"></span><br><span class="line"><span class="meta">@foo</span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">C</span> </span>&#123; ... &#125;</span><br></pre></td></tr></table></figure>
<h2 id="子类使用大驼峰法"><a href="#子类使用大驼峰法" class="headerlink" title="子类使用大驼峰法"></a>子类使用大驼峰法</h2><figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">extension MyFancyList&lt;T&gt; on <span class="built_in">List</span>&lt;T&gt; &#123; ... &#125;</span><br><span class="line"></span><br><span class="line">extension SmartIterable&lt;T&gt; on <span class="built_in">Iterable</span>&lt;T&gt; &#123; ... &#125;</span><br></pre></td></tr></table></figure>
<blockquote>
<p>Version note: Extensions are a Dart 2.7 language feature</p>
</blockquote>
<h2 id="libraries-packages-directories-and-source-files-using-小写字母-下划线"><a href="#libraries-packages-directories-and-source-files-using-小写字母-下划线" class="headerlink" title="libraries, packages, directories, and source files using 小写字母+下划线"></a>libraries, packages, directories, and source files using 小写字母+下划线</h2><figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/// good</span></span><br><span class="line"><span class="keyword">library</span> peg_parser.source_scanner;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">'file_system.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'slider_menu.dart'</span>;</span><br></pre></td></tr></table></figure>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/// bad</span></span><br><span class="line"><span class="keyword">library</span> pegparser.SourceScanner;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">'file-system.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'SliderMenu.dart'</span>;</span><br></pre></td></tr></table></figure>
<h2 id="import-别名使用小写字母-下划线"><a href="#import-别名使用小写字母-下划线" class="headerlink" title="import 别名使用小写字母+下划线"></a>import 别名使用小写字母+下划线</h2><figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/// good</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'dart:math'</span> <span class="keyword">as</span> math;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:angular_components/angular_components'</span></span><br><span class="line">    <span class="keyword">as</span> angular_components;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:js/js.dart'</span> <span class="keyword">as</span> js;</span><br></pre></td></tr></table></figure>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/// bad</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'dart:math'</span> <span class="keyword">as</span> Math;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:angular_components/angular_components'</span></span><br><span class="line">    <span class="keyword">as</span> angularComponents;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:js/js.dart'</span> <span class="keyword">as</span> JS;</span><br></pre></td></tr></table></figure>
<h2 id="标识符使用小驼峰法"><a href="#标识符使用小驼峰法" class="headerlink" title="标识符使用小驼峰法"></a>标识符使用小驼峰法</h2><figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> item;</span><br><span class="line"></span><br><span class="line">HttpRequest httpRequest;</span><br><span class="line"></span><br><span class="line"><span class="keyword">void</span> align(<span class="built_in">bool</span> clearItems) &#123;</span><br><span class="line">  <span class="comment">// ...</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="常量标识符优先使用小驼峰"><a href="#常量标识符优先使用小驼峰" class="headerlink" title="常量标识符优先使用小驼峰"></a>常量标识符优先使用小驼峰</h2><figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/// good</span></span><br><span class="line"><span class="keyword">const</span> pi = <span class="number">3.14</span>;</span><br><span class="line"><span class="keyword">const</span> defaultTimeout = <span class="number">1000</span>;</span><br><span class="line"><span class="keyword">final</span> urlScheme = <span class="built_in">RegExp</span>(<span class="string">'^([a-z]+):'</span>);</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Dice</span> </span>&#123;</span><br><span class="line">  <span class="keyword">static</span> <span class="keyword">final</span> numberGenerator = Random();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/// bad</span></span><br><span class="line"><span class="keyword">const</span> PI = <span class="number">3.14</span>;</span><br><span class="line"><span class="keyword">const</span> DefaultTimeout = <span class="number">1000</span>;</span><br><span class="line"><span class="keyword">final</span> URL_SCHEME = <span class="built_in">RegExp</span>(<span class="string">'^([a-z]+):'</span>);</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Dice</span> </span>&#123;</span><br><span class="line">  <span class="keyword">static</span> <span class="keyword">final</span> NUMBER_GENERATOR = Random();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="您可以使用-SCREAMING-CAPS-来保持与现有代码的一致性"><a href="#您可以使用-SCREAMING-CAPS-来保持与现有代码的一致性" class="headerlink" title="您可以使用 SCREAMING_CAPS 来保持与现有代码的一致性"></a>您可以使用 SCREAMING_CAPS 来保持与现有代码的一致性</h2><ul>
<li><p>当往已经使用了 SCREAMING_CAPS 风格的代码中新增时，继续使用 SCREAMING_CAPS 风格。</p>
</li>
<li><p>当生成与Java代码并行的Dart代码时——例如，在由protobufs生成的枚举类型中，继续使用 SCREAMING_CAPS 风格。</p>
</li>
</ul>
<blockquote>
<p>提示： 最开始版本使用的是 Java 的 SCREAMING_CAPS 风格，由于以下原因，改为小驼峰：</p>
<ul>
<li>SCREAMING_CAPS在很多情况下看起来都很糟糕，特别是对于CSS颜色之类的东西来说，它的enum值就更糟糕了。</li>
<li>常量经常被更改为最终的非const变量，这就需要频繁更改名称。</li>
<li>在enum类型上自动定义的值属性是const和小写的。</li>
</ul>
</blockquote>
<h2 id="首字母缩写词和缩写词的首字母都要大写"><a href="#首字母缩写词和缩写词的首字母都要大写" class="headerlink" title="首字母缩写词和缩写词的首字母都要大写"></a>首字母缩写词和缩写词的首字母都要大写</h2><p>首字母缩写词很难读懂，而且多个相邻的首字母缩写词会导致名称模糊。例如，给定一个以HTTPSFTP开头的名称，就无法判断它是引用HTTPSFTP还是HTTPSFTP。</p>
<p>为了避免这种情况，首字母缩略词和缩写词要像普通单词一样大写，只有两个字母的首字母缩略词除外。(ID和Mr.等两个字母的缩写仍然像单词一样大写。)</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/// good</span></span><br><span class="line">HttpConnectionInfo</span><br><span class="line">uiHandler</span><br><span class="line">IOStream</span><br><span class="line">HttpRequest</span><br><span class="line">Id</span><br><span class="line">DB</span><br></pre></td></tr></table></figure>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/// bad</span></span><br><span class="line">HTTPConnection</span><br><span class="line">UiHandler</span><br><span class="line">IoStream</span><br><span class="line">HTTPRequest</span><br><span class="line">ID</span><br><span class="line">Db</span><br></pre></td></tr></table></figure>
<h2 id="不要为非私有的标识符使用前导下划线"><a href="#不要为非私有的标识符使用前导下划线" class="headerlink" title="不要为非私有的标识符使用前导下划线"></a>不要为非私有的标识符使用前导下划线</h2><p>默认下划线开头的都是私有成员。</p>
<h2 id="不要使用前缀字母"><a href="#不要使用前缀字母" class="headerlink" title="不要使用前缀字母"></a>不要使用前缀字母</h2><p>匈牙利符号和其他方案出现在BCPL时代，那时编译器并没有帮助您理解代码。因为Dart可以告诉您声明的类型、范围、可变性和其他属性，所以没有理由将这些属性编码到标识符名称中。</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/// good</span></span><br><span class="line">defaultTimeout</span><br></pre></td></tr></table></figure>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/// bad</span></span><br><span class="line">kDefaultTimeout</span><br></pre></td></tr></table></figure>
<h2 id="顺序"><a href="#顺序" class="headerlink" title="顺序"></a>顺序</h2><p>为了保持你的文件的前言整洁，我们有一个规定的顺序，指示的部分应该出现在该出现的位置上。每个“部分”之间应该用空行隔开。</p>
<h3 id="使用-improt-时，优先将-dart-系统包放在第三方包之前"><a href="#使用-improt-时，优先将-dart-系统包放在第三方包之前" class="headerlink" title="使用 improt 时，优先将 dart 系统包放在第三方包之前"></a>使用 improt 时，优先将 dart 系统包放在第三方包之前</h3><p>BAD:</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:bar/bar.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:foo/foo.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">'dart:async'</span>;  <span class="comment">// LINT</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'dart:html'</span>;  <span class="comment">// LINT</span></span><br></pre></td></tr></table></figure>
<p>BAD:</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'dart:html'</span>;  <span class="comment">// OK</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:bar/bar.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">'dart:async'</span>;  <span class="comment">// LINT</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:foo/foo.dart'</span>;</span><br></pre></td></tr></table></figure>
<p>GOOD:</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'dart:async'</span>;  <span class="comment">// OK</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'dart:html'</span>;  <span class="comment">// OK</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:bar/bar.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:foo/foo.dart'</span>;</span><br></pre></td></tr></table></figure>
<h3 id="将“package-”导入放在相对路径导入之前"><a href="#将“package-”导入放在相对路径导入之前" class="headerlink" title="将“package:”导入放在相对路径导入之前"></a>将“package:”导入放在相对路径导入之前</h3><p>BAD:</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'a.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'b.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:bar/bar.dart'</span>;  <span class="comment">// LINT</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:foo/foo.dart'</span>;  <span class="comment">// LINT</span></span><br></pre></td></tr></table></figure>
<p>BAD:</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:bar/bar.dart'</span>;  <span class="comment">// OK</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'a.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:foo/foo.dart'</span>;  <span class="comment">// LINT</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'b.dart'</span>;</span><br></pre></td></tr></table></figure>
<p>GOOD:</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:bar/bar.dart'</span>;  <span class="comment">// OK</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:foo/foo.dart'</span>;  <span class="comment">// OK</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">'a.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'b.dart'</span>;</span><br></pre></td></tr></table></figure>
<h3 id="优先将“第三方”“包”导入放在其他导入之前"><a href="#优先将“第三方”“包”导入放在其他导入之前" class="headerlink" title="优先将“第三方”“包”导入放在其他导入之前"></a>优先将“第三方”“包”导入放在其他导入之前</h3><p>BAD:</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:myapp/io.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:myapp/util.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:bar/bar.dart'</span>;  <span class="comment">// LINT</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:foo/foo.dart'</span>;  <span class="comment">// LINT</span></span><br></pre></td></tr></table></figure>
<p>GOOD:</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:bar/bar.dart'</span>;  <span class="comment">// OK</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:foo/foo.dart'</span>;  <span class="comment">// OK</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:myapp/io.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:myapp/util.dart'</span>;</span><br></pre></td></tr></table></figure>
<h3 id="在所有导入之后，请在单独的部分中指定导出"><a href="#在所有导入之后，请在单独的部分中指定导出" class="headerlink" title="在所有导入之后，请在单独的部分中指定导出"></a>在所有导入之后，请在单独的部分中指定导出</h3><p>BAD:</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'src/error.dart'</span>;</span><br><span class="line"><span class="keyword">export</span> <span class="string">'src/error.dart'</span>; <span class="comment">// LINT</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'src/string_source.dart'</span>;</span><br></pre></td></tr></table></figure>
<p>GOOD:</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'src/error.dart'</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="string">'src/string_source.dart'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="string">'src/error.dart'</span>; <span class="comment">// OK</span></span><br></pre></td></tr></table></figure>
<h3 id="按字母顺序对各部分进行排序"><a href="#按字母顺序对各部分进行排序" class="headerlink" title="按字母顺序对各部分进行排序"></a>按字母顺序对各部分进行排序</h3><p>BAD:</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:foo/bar.dart'</span>; <span class="comment">// OK</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:bar/bar.dart'</span>; <span class="comment">// LINT</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">'a/b.dart'</span>; <span class="comment">// OK</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'a.dart'</span>; <span class="comment">// LINT</span></span><br></pre></td></tr></table></figure>
<p>GOOD:</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="string">'package:bar/bar.dart'</span>; <span class="comment">// OK</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'package:foo/bar.dart'</span>; <span class="comment">// OK</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> <span class="string">'a.dart'</span>; <span class="comment">// OK</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'a/b.dart'</span>; <span class="comment">// OK</span></span><br></pre></td></tr></table></figure>
<h2 id="格式化"><a href="#格式化" class="headerlink" title="格式化"></a>格式化</h2><p>与许多语言一样，Dart忽略空白。然而,人类没有。具有一致的空白样式有助于确保人类读者以与编译器相同的方式查看代码。</p>
<h3 id="使用-dartfmt-工具格式化你的代码"><a href="#使用-dartfmt-工具格式化你的代码" class="headerlink" title="使用 dartfmt 工具格式化你的代码"></a>使用 <code>dartfmt</code> 工具格式化你的代码</h3><p>格式化是一项繁琐的工作，在重构过程中尤其耗费时间。幸运的是，你不必为此担心。我们提供了一种复杂的自动代码格式化程序，称为<code>dartfmt</code>，它可以为您完成这项工作。我们有一些关于它所适用的规则的文档，但是dart的官方空格处理规则是由<code>dartfmt</code>生成的。</p>
<p>剩下的格式化指导方针是针对一些<code>dartfmt</code>无法为您解决的问题手动处理。</p>
<h3 id="考虑更改你的代码，使其对格式更友好"><a href="#考虑更改你的代码，使其对格式更友好" class="headerlink" title="考虑更改你的代码，使其对格式更友好"></a>考虑更改你的代码，使其对格式更友好</h3><p>格式化程序尽其所能地处理你扔给它的任何代码，但它不能创造奇迹。如果您的代码有特别长的标识符、深度嵌套的表达式、不同类型的操作符的混合等，格式化的输出可能仍然难以阅读。</p>
<p>当这种情况发生时，重新组织或简化您的代码。考虑缩短局部变量名或将表达式提升为新的局部变量。换句话说，进行与手工格式化代码并使其更具可读性相同的修改。可以将<code>dartmt</code>看作是一种伙伴关系，在这种关系中，您可以一起工作，有时是迭代地工作，以生成漂亮的代码。</p>
<h3 id="避免行超过80个字符"><a href="#避免行超过80个字符" class="headerlink" title="避免行超过80个字符"></a>避免行超过80个字符</h3><p>易读性研究表明，长行文字很难阅读，因为当你移动到下一行的开头时，你的眼睛不得不走得更远。这就是报纸和杂志使用多栏文本的原因。</p>
<p>如果您真的希望行长度超过80个字符，我们的经验是，您的代码可能太过冗长，而且可能更紧凑一些。最主要的冒犯者通常是很长的名字。问问自己，“该类型名称中的每个单词都告诉了我一些重要的信息，还是防止了名称冲突?”如果不是，那就考虑忽略它。</p>
<p>注意，<code>dartfmt</code>为你做了99%的事情，但剩下的1%是你自己。它不会分割长字符串来容纳80个列，所以您必须手动进行分割。</p>
<p>例外:当URI或文件路径出现在注释或字符串中(通常在导入或导出中)，即使它导致行超过80个字符，它也可能保持完整。这使得在源文件中搜索路径变得更加容易。</p>
<p>例外:多行字符串可以包含超过80个字符的行，因为换行在字符串中很重要，将行分割成更短的行可以改变程序。</p>
<h3 id="对所有流控制语句使用大括号"><a href="#对所有流控制语句使用大括号" class="headerlink" title="对所有流控制语句使用大括号"></a>对所有流控制语句使用大括号</h3><p>这样做可以避免悬空else问题。</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (isWeekDay) &#123;</span><br><span class="line">  <span class="built_in">print</span>(<span class="string">'Bike to work!'</span>);</span><br><span class="line">&#125; <span class="keyword">else</span> &#123;</span><br><span class="line">  <span class="built_in">print</span>(<span class="string">'Go dancing or read a book!'</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>例外:当你有一个没有else子句的if语句，并且整个if语句适合在一行，你可以省略大括号，如果你喜欢:</p>
<p><code>if (arg == null) return defaultValue;</code></p>
<p>如果正文换行，则使用大括号:</p>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/// good</span></span><br><span class="line"><span class="keyword">if</span> (overflowChars != other.overflowChars) &#123;</span><br><span class="line">  <span class="keyword">return</span> overflowChars &lt; other.overflowChars;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight dart"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/// bad</span></span><br><span class="line"><span class="keyword">if</span> (overflowChars != other.overflowChars)</span><br><span class="line">  <span class="keyword">return</span> overflowChars &lt; other.overflowChars;</span><br></pre></td></tr></table></figure>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>============ END ============</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.png" alt="段燚涛 微信支付">
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.png" alt="段燚涛 支付宝">
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/规范/" rel="tag"># 规范</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2020/03/11/Dart-语法-1/" rel="next" title="Dart 语法(1)">
                <i class="fa fa-chevron-left"></i> Dart 语法(1)
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2020/03/12/Dart-语法-2/" rel="prev" title="Dart 语法(2)">
                Dart 语法(2) <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
      <div id="lv-container" data-id="city" data-uid="MTAyMC80MzUzNC8yMDA3Mw=="></div>
    </div>

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image" src="/images/avatar.jpeg" alt="段燚涛">
            
              <p class="site-author-name" itemprop="name">段燚涛</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">19</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">6</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">17</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/duanyitao" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mailto:duanyitao7937@gmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                快速链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://github.com/googlesamples/android-architecture/tree/todo-mvvm-databinding/todoapp" title="Android-architecture" target="_blank">Android-architecture</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://developer.android.google.cn/jetpack" title="Jetpack" target="_blank">Jetpack</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#Dart-风格指南"><span class="nav-number">1.</span> <span class="nav-text">Dart 风格指南</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#风格类型"><span class="nav-number">1.1.</span> <span class="nav-text">风格类型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#类型使用大驼峰法"><span class="nav-number">1.2.</span> <span class="nav-text">类型使用大驼峰法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#子类使用大驼峰法"><span class="nav-number">1.3.</span> <span class="nav-text">子类使用大驼峰法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#libraries-packages-directories-and-source-files-using-小写字母-下划线"><span class="nav-number">1.4.</span> <span class="nav-text">libraries, packages, directories, and source files using 小写字母+下划线</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#import-别名使用小写字母-下划线"><span class="nav-number">1.5.</span> <span class="nav-text">import 别名使用小写字母+下划线</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#标识符使用小驼峰法"><span class="nav-number">1.6.</span> <span class="nav-text">标识符使用小驼峰法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#常量标识符优先使用小驼峰"><span class="nav-number">1.7.</span> <span class="nav-text">常量标识符优先使用小驼峰</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#您可以使用-SCREAMING-CAPS-来保持与现有代码的一致性"><span class="nav-number">1.8.</span> <span class="nav-text">您可以使用 SCREAMING_CAPS 来保持与现有代码的一致性</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#首字母缩写词和缩写词的首字母都要大写"><span class="nav-number">1.9.</span> <span class="nav-text">首字母缩写词和缩写词的首字母都要大写</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#不要为非私有的标识符使用前导下划线"><span class="nav-number">1.10.</span> <span class="nav-text">不要为非私有的标识符使用前导下划线</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#不要使用前缀字母"><span class="nav-number">1.11.</span> <span class="nav-text">不要使用前缀字母</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#顺序"><span class="nav-number">1.12.</span> <span class="nav-text">顺序</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#使用-improt-时，优先将-dart-系统包放在第三方包之前"><span class="nav-number">1.12.1.</span> <span class="nav-text">使用 improt 时，优先将 dart 系统包放在第三方包之前</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#将“package-”导入放在相对路径导入之前"><span class="nav-number">1.12.2.</span> <span class="nav-text">将“package:”导入放在相对路径导入之前</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#优先将“第三方”“包”导入放在其他导入之前"><span class="nav-number">1.12.3.</span> <span class="nav-text">优先将“第三方”“包”导入放在其他导入之前</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#在所有导入之后，请在单独的部分中指定导出"><span class="nav-number">1.12.4.</span> <span class="nav-text">在所有导入之后，请在单独的部分中指定导出</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#按字母顺序对各部分进行排序"><span class="nav-number">1.12.5.</span> <span class="nav-text">按字母顺序对各部分进行排序</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#格式化"><span class="nav-number">1.13.</span> <span class="nav-text">格式化</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#使用-dartfmt-工具格式化你的代码"><span class="nav-number">1.13.1.</span> <span class="nav-text">使用 dartfmt 工具格式化你的代码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#考虑更改你的代码，使其对格式更友好"><span class="nav-number">1.13.2.</span> <span class="nav-text">考虑更改你的代码，使其对格式更友好</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#避免行超过80个字符"><span class="nav-number">1.13.3.</span> <span class="nav-text">避免行超过80个字符</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#对所有流控制语句使用大括号"><span class="nav-number">1.13.4.</span> <span class="nav-text">对所有流控制语句使用大括号</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      
        <div class="back-to-top">
          <i class="fa fa-arrow-up"></i>
          
            <span id="scrollpercent"><span>0</span>%</span>
          
        </div>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Build by duanyitao.</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">38.6k</span>
  
</div>









        







        
      </div>
    </footer>

    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  
    <script type="text/javascript">
      (function(d, s) {
        var j, e = d.getElementsByTagName(s)[0];
        if (typeof LivereTower === 'function') { return; }
        j = d.createElement(s);
        j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
        j.async = true;
        e.parentNode.insertBefore(j, e);
      })(document, 'script');
    </script>
  












  





  

  

  

  
  

  
  


  
  <script type="text/javascript" src="/js/src/js.cookie.js?v=5.1.4"></script>
  <script type="text/javascript" src="/js/src/scroll-cookie.js?v=5.1.4"></script>


  
  <script type="text/javascript" src="/js/src/exturl.js?v=5.1.4"></script>


</body>
</html>
